package pulsar;

import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;

public class Sub {
    public static void main(String[] args) throws PulsarClientException {
        PulsarClient client = PulsarClient.builder()
                .serviceUrl("pulsar://192.168.56.101:6650")
                .build();
        Consumer<byte[]> consumer = client.newConsumer().topic("my-topic").subscriptionName("my-sub").subscribe();
        while (true) {
            Message<byte[]> msg = consumer.receive();
            System.out.println("Message received: " + new String(msg.getData()));
            consumer.acknowledge(msg);
        }
    }
}
